var express = require('express');
var router = express.Router();
var db = require('../sql.js');

/* GET users listing. */
router.get('/', function(req, res, next) {
  res.render('index');
});
router.post('/main', function(req, res, next) {
  // 获取用户输入的用户名和密码
  var userName = req.body.userName;
  var userPwd = req.body.userPwd;
  // console.log(req.body.userName);
  db.query( 'select * from user where userName = ? and userPwd = ?'
    ,[userName,userPwd],function(err,result){
      if(err){
        console.log(err);
        return;
      }
      console.log(result);
      if(result.length > 0){
        res.render("main");
      }else{
        res.writeHead(200,{
          'Content-Type':'text/html;charset=utf-8'
        });
        res.write('<head><meta  charset="utf-8"/></head>');
        res.end("输入密码有误");
      }
  })
  
});

module.exports = router;
